package com.fau.wmbj.server.controller;

import com.fau.wmbj.server.config.CurrentUser;
import com.fau.wmbj.server.entity.Menu;
import com.fau.wmbj.server.entity.User;
import com.fau.wmbj.server.service.MenuService;
import com.fau.wmbj.server.utils.Message;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 菜单
 *
 * @author jiawei
 * @version 1.0
 * @datetime 2024-02-28 10:18
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    @RequestMapping("/getUserMenus")
    public Message getUserMenus(@CurrentUser User user) {

        return Message.success(menuService.getAllMenus());
    }

    @RequestMapping("/getAllMenus")
    public Message getAllMenus() {

        return Message.success(menuService.getAllMenus());
    }

    @GetMapping("/getRoleMenus/{roleId}")
    public Message getRoleMenus(@PathVariable("roleId") Long roleId) {

        return Message.success(menuService.getRoleMenus(roleId));
    }

    @GetMapping("/getCompanyMenus/{companyId}")
    public Message getCompanyMenus(@PathVariable("companyId") Long companyId) {

        return Message.success(menuService.getCompanyMenus(companyId));
    }


    @RequestMapping("/update")
    public Message update(@RequestBody Menu menu) {
        menuService.updateMenu(menu);
        return Message.success();
    }

}
